package com.sxfq.loansupermarket.backsystem.modular.system.service.impl;

import com.sxfq.loansupermarket.backsystem.common.persistence.model.Deptinfos;
import com.sxfq.loansupermarket.backsystem.common.persistence.model.Test;
import com.sxfq.loansupermarket.backsystem.common.persistence.model.Userinfos;
import com.sxfq.loansupermarket.backsystem.core.shiro.ShiroKit;
import com.sxfq.loansupermarket.backsystem.core.util.StringUtil;
import com.sxfq.loansupermarket.backsystem.modular.system.dao.LoginDao;
import com.sxfq.loansupermarket.backsystem.modular.system.service.ILoginService;
import com.sxfq.loansupermarket.backsystem.modular.weixin.entity.ExtenAccountInfo;
import com.sxfq.loansupermarket.backsystem.modular.weixin.entity.WhUrlInfo;
import com.sxfq.loansupermarket.backsystem.modular.weixin.entity.WxTokenInfo;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.Map;

/**
 * 菜单服务
 *
 * @author fengshuonan
 * @date 2017-05-05 22:20
 */
@Service
public class LoginServiceImpl implements ILoginService {
    @Resource
    LoginDao loginDao;

    public void toIndex() {

    }

    public Deptinfos getDept() {
        Map<String, Object> params = new HashMap<String, Object>();
        if (StringUtil.isNotEmpty(ShiroKit.getUser().getOutpatientName())) {
            params.put("simplename", ShiroKit.getUser().getOutpatientName());
        }
        return loginDao.getDept(params);
    }

    public Userinfos getUser() {
        Map<String, Object> params = new HashMap<String, Object>();
        if (StringUtil.isNotEmpty(ShiroKit.getSessionAttr("username"))) {
            params.put("account", ShiroKit.getSessionAttr("username"));
        }
        if (StringUtil.isNotEmpty(ShiroKit.getUser().getOutpatientName())) {
            params.put("simplename", ShiroKit.getUser().getOutpatientName());
        }
        return loginDao.getUser(params);
    }

    public Test getTest() {
        return loginDao.getTest();
    }

    public WxTokenInfo getWxToken(String areaAbbreviation) {
        Map<String, Object> params = new HashMap<String, Object>();
        if (StringUtil.isNotEmpty(areaAbbreviation)) {
            params.put("areaAbbreviation", areaAbbreviation);
        }
        return loginDao.getWxToken(params);
    }

    public WhUrlInfo getWhIpInfo(){
        return loginDao.getWhIpInfo();
    }

    public ExtenAccountInfo getExten(String account){
        Map<String, Object> params = new HashMap<String, Object>();
        if (StringUtil.isNotEmpty(account)) {
            params.put("account", account);
        }
        return loginDao.getExten(params);
    }

    public Userinfos getUserinfos() {
        Map<String, Object> params = new HashMap<String, Object>();
        if (StringUtil.isNotEmpty(ShiroKit.getSessionAttr("username"))) {
            params.put("account", ShiroKit.getSessionAttr("username"));
        }
        return loginDao.getUserinfos(params);
    }

    public Deptinfos getDeptinfos() {
        Map<String, Object> params = new HashMap<String, Object>();
        if (StringUtil.isNotEmpty(ShiroKit.getUser().getOutpatientName())) {
            params.put("simplename", ShiroKit.getUser().getOutpatientName());
        }
        return loginDao.getDeptinfos(params);
    }
}
